package cn.edu.nju.software.cdiy.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import cn.edu.nju.software.cdiy.bean.Scheme;
import cn.edu.nju.software.cdiy.dao.SchemeDao;
import cn.edu.nju.software.cdiy.service.SchemeService;
import cn.edu.nju.software.cdiy.service.UtilService;
import cn.edu.nju.software.cdiy.util.Item;
import cn.edu.nju.software.cdiy.util.SortType;
import cn.edu.nju.software.cdiy.util.SortWay;

public class SchemeServiceImpl implements SchemeService {

	@Autowired
	private SchemeDao schemeDao;
	@Autowired
	private UtilService utilService;

	public void setSchemeDao(SchemeDao schemeDao) {
		this.schemeDao = schemeDao;
	}

	public void setUtilService(UtilService utilService) {
		this.utilService = utilService;
	}

	@Override
	public Scheme save(Scheme scheme) {
		return schemeDao.save(utilService.fillScheme(scheme));
	}

	@Override
	public boolean deleteScheme(long id) {
		return schemeDao.deleteSchemeByState(id);
	}

	@Override
	public Scheme getSchemeById(Long id) {
		return schemeDao.getSchemeById(id);
	}

	@Override
	public List<Scheme> getAllScheme() {
		return schemeDao.loadAllScheme();
	}

	@Override
	public List<Scheme> searchSchemeByName(String name) {
		return schemeDao.searchBySchemeName(name);
	}

	@Override
	public List<Scheme> getFourScheme(int hardwareId, String hardwareType) {
		return schemeDao.getFourScheme(hardwareId, hardwareType);
	}

	@Override
	public Map<String,List<Item>> getFilterBoard() {
		return schemeDao.getFilterBoard();
	}

	@Override
	public List<Scheme> filter(List<Integer> brandList, List<Integer> priceList, 
			List<Integer> typeList, SortType st, SortWay sw, int page) {
		return schemeDao.filter(brandList, priceList, typeList, st, sw, page);
	}

	@Override
	public long getFilterResultLength(List<Integer> brandList, List<Integer> priceList, List<Integer> typeList) {
		return schemeDao.getFilterResultLength(brandList, priceList, typeList);
	}

	@Override
	public Map<String, List<Scheme>> getBrandRankLists() {
		return schemeDao.getBrandLists();
	}

	@Override
	public Map<String, List<Scheme>> getPriceRankLists() {
		return schemeDao.getPriceLists();
	}

	@Override
	public Map<String, List<Scheme>> getTypeRankLists() {
		return schemeDao.getTypeLists();
	}

	@Override
	public List<Scheme> getSaleRankList() {
		return schemeDao.getSaleList();
	}

	@Override
	public List<Scheme> getTimeRankList() {
		return schemeDao.getTimeList();
	}

	@Override
	public Map<String, List<Scheme>> getRelatedSchemes(Scheme scheme) {
		return schemeDao.getRelatedLists(scheme);
	}

}
